import request from '@/utils/request'
import { getToken } from '@/utils/auth'

export const updateUserInfo = data => {
  const token = getToken()
  return request({
    url: '/user/updateUserInfo', // 使用一个不包含用户 ID 的 URL
    method: 'PATCH',
    data,
    headers: {
      token: token
    }
  })
}

// 根据token获取用户信息
export function getUserInfoByToken(token) {
  return request({
    url: '/user/getUserInfo',
    method: 'get',
    headers: {
      token : token
    }
  })
}

//上传头像
export const uploadUserAvatar = file => {
  const token = getToken()
  const formData = new FormData()
  formData.append('avatar', file)

  return request({
    url: '/user/uploadAvatar',
    method: 'POST',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data',
      token: token
    }
  })
}
export const checkMobileOrEmail = data => {
  const token = getToken()
  //console.log(token)  
  return request({
    url: '/login/checkMobileOrEmail',
    method: 'POST',
    data,
    headers: {
      token: token
    }
  })
}
